package com.eascs.admin.o2o.internal.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.eascs.admin.common.dao.BaseO2oDao;
import com.eascs.admin.o2o.internal.entity.AuditComments;
import com.eascs.admin.o2o.internal.util.BaseUtils;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;

/**
 * 
 * 内审审批表单历史记录表
 *
 */
@Repository
public class AuditCommentsDao extends BaseO2oDao{
	/**
	 * 查询  内审审批列表分页
	 * @param df
	 * @param pageSize
	 * @param pageIndex
	 * @return
	 */
	public PageResult<AuditComments> queryListPage(AuditComments df, int pageSize, int pageIndex){
		StringBuffer sb=new StringBuffer("select * from o2o_auditcomments od where 1=1 and od.del_flag='0'");
		SqlPageQuery<AuditComments> sqlPageQuery=new SqlPageQuery<AuditComments>(AuditComments.class, pageSize, pageIndex,sb.toString());
		return this.findDataWithPage(sqlPageQuery);
	}
	/**
	 * 删除内审审批列表
	 * @param auditComments
	 */
	public void delete(AuditComments auditComments){
		String sql="update o2o_auditcomments t set t.del_flag='"+BaseUtils.Y_DEL_FLAG+"' where t.id='"+auditComments.getAuNo()+"'";
		this.execute(sql);
	}
	/**
	 * 查询  内审审批列表
	 * @param loanapplyNo
	 * @return
	 */
	public PageResult<Object[]> findAuditList(String loanapplyNo) {
		String sql = "select t.ea_mount,concat(cast((t.generalrate*100)as decimal(10,2)),'%'),t.bank_loan_name,t.payment_type,"
				+ "t.loanterm,t.repaymentway,concat(cast((t.risk*100)as decimal(10,4)),'%')as risk,"+
				"concat(cast((t.depositrate*100)as decimal(10,2)),'%'),"+
				"concat(cast((t.managefeerate*100)as decimal(10,2)),'%'),"+"concat(cast((t.loanrate*100)as decimal(10,4)),'%'),"+
				"t.emp_loye_name,t.createdate,"+
				"t.remark from  o2o_auditcomments t where t.loanapply_no=? order by t.createdate desc";
		SqlPageQuery<Object[]> pageQuery = new SqlPageQuery<>(Object[].class, 50, 0);
		pageQuery.addParam(loanapplyNo);
		pageQuery.setQuerySql(sql);
		return this.findDataWithPage(pageQuery);
	}
	/**
	 * 查询内审审批记录
	 * @param loanapplyNo
	 * @return
	 */
	public List<AuditComments> queryAuditCommentsList(String loanapplyNo){
		String sql="select * from o2o_auditcomments od where od.loanapply_no=? order by createdate desc";
		return this.findEntitys(sql, AuditComments.class, loanapplyNo);
	}
	/**
	 * 查询审核人姓名 是否保存过 内审表单数据
	 * @param loanapplyNo
	 * @param auditorId
	 * @return
	 */
	public List<AuditComments> queryUserNo(String loanapplyNo, String auditorId) {
		String sql="select * from o2o_auditcomments od where od.loanapply_no=? and od.emp_loye_no=?";
		return this.findEntitys(sql, AuditComments.class, loanapplyNo,auditorId);
	}
}
